package com.yuerlive.rainbow.module.playlive;

import android.graphics.drawable.BitmapDrawable;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.yuerlive.rainbow.R;
import com.yuerlive.rainbow.base.BaseActivity;
import com.yuerlive.rainbow.base.BasePresenter;
import com.yuerlive.rainbow.entity.CloseData;
import com.yuerlive.rainbow.entity.User;
import com.yuerlive.rainbow.module.playlive.presenter.LiveEndContract;
import com.yuerlive.rainbow.module.playlive.presenter.LiveEndPresenter;
import com.yuerlive.rainbow.utils.BitmapUtil;
import com.yuerlive.rainbow.utils.FormatUtil;
import com.yuerlive.rainbow.utils.GlideUtil;
import com.yuerlive.rainbow.utils.UserProxy;
import com.yuerlive.rainbow.widget.timeselector.TextUtil;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by xiaoyi on 2017/6/12.
 */

public class LiveEndActivity extends BaseActivity<LiveEndContract.Presenter> implements LiveEndContract.View {
    @BindView(R.id.imgLiveCover)
    ImageView imgLiveCover;
    @BindView(R.id.tvLiveTimes)
    TextView tvLiveTimes;
    @BindView(R.id.tvWatchCount)
    TextView tvWatchCount;
    @BindView(R.id.tvSubscribeCount)
    TextView tvSubscribeCount;
    @BindView(R.id.tvCharmCount)
    TextView tvCharmCount;
    @BindView(R.id.returnHome)
    Button returnHome;

    private long liveTimes;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_liveend;
    }

    @Override
    protected void initViews() {
        imgLiveCover.setDrawingCacheEnabled(true);
        liveTimes = getIntent().getLongExtra("liveTimes", 0);
        tvLiveTimes.setText("直播时长 " + FormatUtil.formatTime(liveTimes, "HH:mm:ss"));
        presenter = new LiveEndPresenter(this);
        presenter.closeLive();
        User user = UserProxy.getUser();
        String conver = user.getUserInfo().getLiveIcon();
        if (TextUtil.isEmpty(conver)) {
            conver = user.getUserInfo().getIcon();
        }
        GlideUtil.loadBlur(this, conver, imgLiveCover);
       // imgLiveCover.setImageBitmap(BitmapUtil.fastblur(((BitmapDrawable) imgLiveCover.getDrawable()).getBitmap(), 20));
    }

    @OnClick({R.id.returnHome})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.returnHome:
                finish();
                break;
        }
    }


    @Override
    public void setPresenter(LiveEndContract.Presenter presenter) {
        this.presenter = presenter;
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showCloseInfo(CloseData closeInfo) {
        if (closeInfo != null) {
            tvCharmCount.setText("" + closeInfo.getCharmNum());
            tvSubscribeCount.setText("" + closeInfo.getSubscribeNum());
            tvWatchCount.setText("" + closeInfo.getPeopleNum());
        }
    }
}
